package com.example.sys.service;

import com.example.common.utils.BeanUtils;
import com.example.common.utils.IdUtils;
import com.example.sys.dao.SysRoleRepository;
import com.example.sys.entity.dto.RoleDto;
import com.example.sys.entity.po.SysRole;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service
public class RoleService {
    @Resource
    private IdUtils idUtils;
    @Resource
    private SysRoleRepository sysRoleRepository;

    public void insertRole(RoleDto roleDto) {
        SysRole sysRole = BeanUtils.facade().map(roleDto, SysRole.class);
        {
            sysRole.setRoleId(idUtils.nextId());
            sysRole.setStatus(1);
            sysRole.setShowOrder(sysRoleRepository.findFirstByOrderByShowOrderDesc().getShowOrder() + 1);
            sysRole.setCreateTime(LocalDateTime.now());
        }
        sysRoleRepository.save(sysRole);
    }
}
